import React, { Suspense } from 'react'
import {
  // BrowserRouter as Router,
  Router,
  Route,
  Switch,
  Redirect,
} from 'react-router-dom'
// import Layout from './pages/Layout'
// import Login from './pages/Login'
import AuthRoute from './components/AuthRoute/index'
import history from 'utils/history'
import ArticlePublish from 'pages/ArticlePublish'
const Login = React.lazy(() => import('pages/Login'))
const Layout = React.lazy(() => import('pages/Layout'))
// import { hasToken } from 'utils/storage'
function App() {
  return (
    <Router history={history}>
      <div className="App">
        <Suspense fallback={<div>loading...</div>}>
          <Switch>
            <Redirect from="/" to="/home" exact></Redirect>
            {/* path="/home" component={Home} 动态传入 AuthRoute */}
            <AuthRoute path="/home" component={Layout}></AuthRoute>
            {/* <Route
            path="/home"
            render={(props) => {
              if (hasToken()) {
                return <Layout {...props}></Layout>
              } else {
                return <Redirect to="/login"></Redirect>
              }
            }}
          ></Route> */}
            <Route path="/login" component={Login}></Route>
            {/* <Route path="/login" render={(props) => <Login {...props} />}></Route> */}
            <Route
              path="/home/publish"
              exact
              component={ArticlePublish}
            ></Route>
          </Switch>
        </Suspense>
      </div>
    </Router>
  )
}

export default App
